﻿using System.Data;

using FreeSql;

namespace Tszy.Unlimited.Data.FreeSQL;

public interface IFreeSQLUnitOfWorkFactory
{
    /// <summary>
    /// 创建工作单元。
    /// </summary>
    /// <param name="propagation">事务传播方式。</param>
    /// <param name="isolationLevel">事务隔离级别。</param>
    /// <returns></returns>
    IUnitOfWork Begin(Propagation propagation = Propagation.Required, IsolationLevel? isolationLevel = null);
}

public class FreeSQLUnitOfWorkFactory : IFreeSQLUnitOfWorkFactory
{
    private readonly UnitOfWorkManager _unitOfWorkManager;

    public FreeSQLUnitOfWorkFactory(UnitOfWorkManager unitOfWorkManager)
    {
        _unitOfWorkManager = unitOfWorkManager;
    }

    public IUnitOfWork Begin(Propagation propagation = Propagation.Required, IsolationLevel? isolationLevel = null) => _unitOfWorkManager.Begin(propagation, isolationLevel);
}